import QtQuick 2.13
import QtQml 2.14
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.3

import org.kde.kirigami 2.14 as Kirigami
import org.mauikit.controls 1.3 as Maui
import "../../../templates"

CardButton
{
    id: control
    implicitHeight: 48
    implicitWidth: Math.max(_template.implicitWidth, implicitHeight)
    property alias template : _template

    display: ToolButton.IconOnly

    property Component page : null

    contentItem: Maui.ListItemTemplate
    {
        id: _template
        labelsVisible: (label1.text.length || label2.text.length) && control.display === ToolButton.TextBesideIcon
        label1.text: control.text
        iconSource: control.icon.name
        isMask: false
        iconVisible: true
        iconSizeHint: Maui.Style.iconSizes.medium
        headerSizeHint: control.implicitHeight

        Loader
        {
            asynchronous: true
            active: control.page
            visible: active
            Layout.preferredHeight: 16
            Layout.preferredWidth: height
            sourceComponent: Item
            {
                Kirigami.Icon
                {
                    color: Kirigami.Theme.textColor
                    anchors.centerIn: parent
                    source: "arrow-right"
                    height: 8
                    width: 8
                }
            }
        }
    }
}
